/**
 * Zhznet.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.liwei.httpclient.demo;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 *
 * @author Liwei
 * @version $Id: BasicAuthenticationExample.java, v 0.1 2011-1-22 下午09:27:48 Liwei Exp $
 */
public class BasicAuthenticationExample {

    public BasicAuthenticationExample() {
    }

    public static void main(String[] args) throws Exception {
        HttpClient client = new HttpClient();
        client.getState().setCredentials("www.verisign.com", "realm",
            new UsernamePasswordCredentials("username", "password"));

        GetMethod get = new GetMethod("https://www.verisign.com/products/index.html");
        get.setDoAuthentication(true);
        int status = client.executeMethod(get);
        System.out.println(status + "\n" + get.getResponseBodyAsString());
        get.releaseConnection();
    }
}
